package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @version V1.0
 * @author: yongjichu
 * @date: 2020/2/10 14:49
 * @description:
 */
@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {
    @Autowired
    MemberDao memberDao;
    @Override
    public List<Integer> findMemberReport(List<String> months) {
        //创建一个集合
        List<Integer> memberCountList=new ArrayList<>();
        //遍历months集合
        for (String month : months) {
            //这里的monyh就是集合中的数据，如2019-02，把这个数据拼接 -31，因为我们要使用 2019-02-31这种形式查询数据
            month=month+"-31";
            Integer count=memberDao.findMemberCount(month);
            memberCountList.add(count);
        }
        return memberCountList;
    }
    /**
     * 获取订单数与订单详情用于制作套餐报表
     * @return
     */
    @Override
    public List<Map> getSetmealReport() {
        List<Map> mapList=memberDao.getSetmealReport();
        return mapList;
    }

    /**
     * 根据性别制作报表
     *
     * @return
     */
    @Override
    public List<Map> getMemberBySexReport() {
        List<Map> mapList=memberDao.getMemberBySexReport();
        return mapList;
    }

    /**
     * 根据年龄段做报表
     *
     * @return
     */
    @Override
    public List<Map> getMemberByAgeReport() {
        List<Map> mapList=memberDao.getMemberByAgeReport();
        return mapList;
    }
}
